package  
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author Ivan
	 */
	public class TileSet extends EventDispatcher
	{
		
		public static var LOADED:String = "BITMAP_LOADED";
		
		public function TileSet(xml:XML) 
		{
			width = xml.@tilewidth;
			height = xml.@tileheight;
			firstgid = xml.@firstgid;
			
			loader = new Loader();
			loader.load(new URLRequest(xml.image.@source));
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
		}
		
		private function onComplete(e:Event):void
		{
			bitmapData = (loader.content as Bitmap).bitmapData;
			dispatchEvent(new Event(LOADED));
		}
		
		public var width:int;
		public var height:int;
		public var firstgid:int;
		public var bitmapData:BitmapData;
		
		private var loader:Loader;
		
	}

}